package com.toggery.POS.service;

import com.toggery.POS.entity.Category;
import com.toggery.POS.entity.Clothing;
import com.toggery.POS.entity.Test;
import com.toggery.POS.dao.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Autowired
    CategoryMapper mapper ;

    public List<Category> findAll(){
        return  mapper.findAll();
    }
    public boolean save(Category category){
        if(mapper.findById(category.getId())==null){
            mapper.insert(category);
            return true;
        }else {
            return false;
        }

    }
    public boolean updateCategory(Category category){
        if(mapper.updateByPrimaryKey(category)>0){
            return true;
        }else {
            return false;
        }
    }
    public boolean deleteById(int id){
        if(mapper.deleteByPrimaryKey(id)>0){
            return true;
        }else {
            return false;
        }
    }
    public Category findById(int id){
        return mapper.findById(id);
    }
//    精确查询
    public Category findByName(String name){
        return mapper.findByName(name);
    }
//    模糊查询
    public List<Category> findLikeName(String name){
        //加上通配符
        name = "%"+name+"%";
        return mapper.findLikeName(name);
    }


}
